Skip to content

Conversation

@stevenctl
Copy link

@stevenctl stevenctl commented Dec 6, 2025

fixes #122

This PR adds a new method that allows executing all statements in a given string. More context is in the issue.

// bikeshedding on the name is very welcome!
Future<void> executeMultiple(String sql, [List<Object?> paramters = const []]) async

Based on feedback, I've updated the PR to just use execute which doesn't require any changes to the core sqlite3 package. However, I still believe this functionality needs a new API. It is valid to expect a ResultSet from the vanilla execute. I don't think there is a way to modify that signature to add settings here. The only way to avoid adding an API here

Also, using execute means that it is valid after all to pass parameters. Using params.isEmpty/isNotEmpty is probably not a good way to decide whether the user can expect a result back (it's perfectly valid to expect a result from INSERT INTO mytable (something) RETURNING id.

This is implemented using prepareMultiple from the sqlite3 package.

For web support, an additional PR (simolus3/sqlite3.dart#337) was required in that repo/package. For now I left a dependency override that should be removed before merging.


// Execute a query that potentially contains multiple statements.
Future<void> executeMultiple(String sql,
[List<Object?> parameters = const []]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For executeMultiple, we should probably remove the parameters argument like you mentioned in the issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm misreading the sqlite3 package, I should be possible to do something like

executeMultiple(
  "INSERT INTO books VALUES (?, ?); INSERT INTO authors (?);",
   ["Sqlite for Dummies", "simolus3", "simolus3"],
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that would work, if you call execute with parameters it will only prepare a single statement.

Now, we could potentially make that work by tracking how many parameters each statement has and then skipping those, but it gets trickier if parameters have explicit indexes (INSERT INTO books VALUES (?, ?2); INSERT INTO authors (?2);) or names (VALUES (:title, :author); INSERT INTO authors (:author)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: execute multiple statments in one call

2 participants